package homework.day05;

import java.io.*;

/**
 * 将当前目录下的所有obj文件获取到，并进行
 * 反序列化后输出每个用户的信息(直接输出反序
 * 列化后的User对象即可)
 *
 * @author Xiloer
 */
public class Test03 {
    public static void main(String[] args) {
        File dir = new File(".");
        if (dir.isDirectory()) {
//            FileFilter fileFilter = new FileFilter() {
//                @Override
//                public boolean accept(File file) {
//                    return file.getName().contains("obj");
//                }
//            };
            File[] files = dir.listFiles(f -> f.getName().contains("obj"));
            for (int i = 0; i < files.length; i++) {
                String name = files[i].getName();
                try (
                        FileInputStream fis = new FileInputStream(name);
                        ObjectInputStream ois = new ObjectInputStream(fis);
                ) {
                    Object o = ois.readObject();
                    System.out.println(o);
/*                    if(o instanceof User){
                        User u = (User)o;
                        System.out.println(u);
                    }
                   */

                } catch (IOException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
